package com.twu.biblioteca.menu;

import com.twu.biblioteca.*;

public class ListMoviesMenuItem implements MenuItem {
    @Override
    public String getName() {
        return "List Movies";
    }

    @Override
    public String getMnemonic() {
        return "ml";
    }

    @Override
    public PostMenuItemAction execute(Library library, UserIO io, UserRepository repository) {
        io.println("Movies available:");
        int moviesAvailable = 0;

        for (Movie movie : library.getMovies()) {
            if (!movie.isCheckedOut()) {
                io.print(String.format("%-50s %-30s %-4s   ", movie.getTitle(), movie.getDirector(), movie.getYearReleased()));

                if (movie.isUnrated()) {
                    io.println("Unrated");
                } else {
                    io.println(String.format("%s / 10", movie.getRating()));
                }

                moviesAvailable++;
            }
        }

        if (moviesAvailable == 0) {
            io.println("There are no movies available.");
        }

        return PostMenuItemAction.Continue;
    }

    @Override
    public boolean shouldDisplay(User currentUser) {
        return true;
    }

    @Override
    public int getPriority() {
        return MenuItem.PRIORITY_MOVIES;
    }
}
